//============================================================================
// Name        : getWebPage.cpp
// Author      : alex2stf
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <fstream>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <stdio.h>
#include "curl/curl.h"
#include "curl/easy.h"


#include "WebUtils.h";

using namespace std;

//int writer(char *data, size_t size, size_t nmemb, string *buffer){
//	fprintf(stderr,"Hello I am a function pointer\n");
//	int result = 0;
//	if(buffer != NULL) {
//		buffer -> append(data, size * nmemb);
//		result = size * nmemb;
//	}
//	return result;
//}


int main() {

	//WebTools tools;
	//cout << tools.GetWebPageData("http://stackoverflow.com/questions/1053099/how-can-i-get-content-of-web-page") << endl;
	//stn_getWebPageData();
	cout << stn_getWebPageData("http://stackoverflow.com/questions/1053099/how-can-i-get-content-of-web-page").getNumberOfLines() << endl;
	cout << stn_getWebPageData("http://stackoverflow.com/questions/1053099/how-can-i-get-content-of-web-page").getWebContent() << endl;
	return 0;
	//
//	CURL *curl;
//	CURLcode res;
//	string buffer;		/* See: CURLOPT_WRITEDATA */
//
//	curl=curl_easy_init();
//	if(curl){
//		cout << "!!!Curl Easy init!!!" << endl; // prints !!!Hello World!!!
//
//
//		curl_easy_setopt (curl, CURLOPT_URL, "http://stackoverflow.com/questions/1053099/how-can-i-get-content-of-web-page");
//		curl_easy_setopt(curl, CURLOPT_HEADER, 0);	 /* No we don't need the Header of the web content. Set to 0 and curl ignores the first line */
//		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0); /* Don't follow anything else than the particular url requested*/
//		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);	/* Function Pointer "writer" manages the required buffer size */
//		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer ); /* Data Pointer &buffer stores downloaded web content */
//
//		res = curl_easy_perform (curl);
//		curl_easy_cleanup (curl);
//
//		std::istringstream iss(buffer);
//		string line, item;
//		int linenum = 0;
//
//		while (getline (iss, line)){
//		        linenum++;													/* Move to Next Line */
//		        cout << "\nLine #" << linenum << ":" << endl;				/* Terminal Printout */
//		        std::istringstream linestream(line);						/* Read Next Line */
//		        int itemnum = 0;
//		        while (getline (linestream, item, ',')){
//		            itemnum++;
//		            cout << "Item #" << itemnum << ": " << item << endl;	/* Terminal Printout */
//		        } // End WHILE (items)
//		    } //End WHILE (lines)
//	}else{
//		cout << "!!!Curl FAILED!!!" << endl; // prints !!!Hello World!!!
//	}
//
//
//	return 0;
}
